/*
* $Id: VisualManager.cpp 143 2010-09-09 19:55:18Z volok-aleksej@yandex.ru $
*
* Copyright 2008 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "VisualManager.h"
#include "MainWin.h"
#include "Settings/SettingsVisualComponent.h"

#include "Common/RefObject.h"
CRefObject<CVisualManager> g_VisualManager;
IVisualManager* IVisualManager::GetVisualManager(){
	return g_VisualManager.GetObject();
}

CVisualManager::CVisualManager(){}
CVisualManager::~CVisualManager(){}

void CVisualManager::Init(){
	m_pMainWin = NULL;
	std::vector<IComponent*> aComponents = IApplication::GetApp()->GetComponents();
	for(std::vector<IComponent*>::const_iterator it = aComponents.begin(); it != aComponents.end(); it++)
		m_aVisualComponents.insert(std::make_pair((*it)->GetNameComponent(), (*it)->GetVisualComponent()));
}

IWnd* CVisualManager::GetMainWindow(){
	if(!m_pMainWin){
		std::vector<IVisualComponent*> aVisualComponents;
		for(std::map<std::tstring, IVisualComponent*>::iterator it = m_aVisualComponents.begin(); it != m_aVisualComponents.end(); it++)
			aVisualComponents.push_back(it->second);
		m_pMainWin = new CMainWin(aVisualComponents);
	}
	return dynamic_cast<IWnd*>(m_pMainWin);
}

IVisualComponent* CVisualManager::GetVisualComponent(const std::tstring& strComponentName){
	std::map<std::tstring, IVisualComponent*>::iterator it = m_aVisualComponents.find(strComponentName);
	if(it == m_aVisualComponents.end()){
		return NULL;}
	return it->second;
}

void CVisualManager::UpdateVisualComponents(){
	for(std::map<std::tstring, IVisualComponent*>::iterator it = m_aVisualComponents.begin(); it != m_aVisualComponents.end(); it++)
		it->second->UpdateComponent();
}